<template>
	<view class="content">
		<u-cell url="/pages/mine/updateInfo" :border="false" :customStyle="{borderBottom: '1rpx solid #232639'}">
			<text slot="title" class="title">个人资料</text>
			<u-icon name="arrow-right" slot="value" color="#ffffff"></u-icon>
		</u-cell>
		<u-cell url="/pages/mine/realname" :border="false" :customStyle="{borderBottom: '1rpx solid #232639'}">
			<text slot="title" class="title">我的认证</text>
			<u-icon name="arrow-right" slot="value" color="#ffffff"></u-icon>
		</u-cell>
		<u-cell url="/pages/setting/safe" :border="false" :customStyle="{borderBottom: '1rpx solid #232639'}">
			<text slot="title" class="title">帐户安全</text>
			<u-icon name="arrow-right" slot="value" color="#ffffff"></u-icon>
		</u-cell>
		<u-cell url="/pages/setting/privacy" :border="false" :customStyle="{borderBottom: '1rpx solid #232639'}">
			<text slot="title" class="title">隐私设置</text>
			<u-icon name="arrow-right" slot="value" color="#ffffff"></u-icon>
		</u-cell>
		<u-cell :border="false" :customStyle="{borderBottom: '1rpx solid #232639'}">
			<text slot="title" class="title">客服热线</text>
			<u-icon name="arrow-right" slot="value" color="#ffffff"></u-icon>
		</u-cell>
		<u-cell :border="false" :customStyle="{borderBottom: '1rpx solid #232639'}" @click="getAppInfo(1)">
			<text slot="title" class="title">检查更新</text>
			<u-badge type="error" slot="value" class="badge" :isDot="Appinfor.showBage || false" ></u-badge>
		</u-cell>
		<button class="btn" @click="loginOut">退出登录</button>
	</view>
</template>

<script>
	import {
		checkUpdate
	} from "@/components/yzhua006-update/js/app-update-check.js";
	import {
		mapActions,
		mapMutations
	} from "vuex";
	export default {
		data() {
			return {
				Appinfor: {
					vsCode: null,
					vsName: null,
					showBage:false,
					force:0,
				}
			}
		},
		onLoad() {
			// #ifdef APP-PLUS
			plus.runtime.getProperty(plus.runtime.appid, widgetInfo => {
				this.Appinfor.vsCode = widgetInfo.versionCode;
				this.Appinfor.vsName = widgetInfo.versionName;
				this._versionApp();
			});
			// #endif
		},
		methods: {
			...mapMutations('user', ['LOGOUT']),
			...mapActions('common', ['versionApp']),
			getAppInfo(type) {
				const system_info = uni.getSystemInfoSync();
				let params = {
					os: system_info.platform //本机设备操作系统  （android || ios）
				}
				if (params.os != 'ios' && params.os != 'android') false; //如果不是安卓或ios 返回false

				//这里自行请求API获取版本信息 建议传入操作系统标识，返回本机对应的操作系统最新版本信息，也就是安卓的返回就是安卓的版本信息  ios返回就是ios的版本信息
				//请求获取最新版本
				this.versionApp().then(res => {
					let update_info = {
						version: res.data.versionName, //线上版本
						now_url: params.os == 'android' ? res.data.androidUrl : res.data.iosUrl, //更新链接
						silent: 0, //是否是静默更新
						force: res.data.forceUpdate, //是否是强制更新
						net_check: 1, //非WIfi是否提示
						note: res.data.versionInfo, //更新内容
					}
					checkUpdate(update_info, type).then(res => {
						if (res.msg) {
							plus.nativeUI.toast(res.msg);
						}
					}); ///检查更新
					//checkUpdate 这个方法会做什么？：线上版本号 与 本地版本号做对比 ，如果需要更新  根据静默，强制、wifi等信息执行静默更新或跳转到升级页面
					//跳转升级页面的前提是，需要新建并在pages.json中配置升级页面，配置方法请查看插件详情
				})
			},
			_versionApp() {
				this.versionApp().then(res => {
					this.Appinfor.showBage = this.Appinfor.vsCode < res.data.versionCode  ? true : false;
				})
			},
			loginOut() {
				this.LOGOUT();
				uni.switchTab({
					url: '/pages/home/index'
				})
				this.$store.state.user.token = '';
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		.title {
			color: #ffffff;
		}
		.flex{
			display: flex;
			align-items: center;
		}
		.badge{
			margin-right: 8rpx;
		}
		.btn {
			background-color: transparent;
			border: 1rpx solid #bf8fef;
			width: 50%;
			color: #bf8fef;
			border-radius: 50rpx;
			font-size: 28rpx;
			margin-top: 80rpx;
		}
	}
</style>
